package Dramaton
{
	import flash.display.MovieClip;

	import flash.text.TextFormat;

	internal class TalkBalloon {
//Build the Word Balloon Text Field
	private var _container_mc:MovieClip;  
	private var _balloon_mc:MovieClip;
	private var _balloonWidth:Number;
	private var _balloonHeight:Number;
	private var _balloonFormat:TextFormat ;
	private var _fillColor:Number;  
	private var _lineColor:Number;
	private var _lineWidth:Number;
	private var _stageWidth:Number;  
	private var _stageHeight:Number;
	private var TEXTMARGIN:Number; // Margin within talk balloon for text placement
	private var STAGEBALLOONMARGIN:Number; // Margin around stage within which balloons must stay
	private var ACTORBALLOONMARGIN:Number; // Margin above actor to offset talk balloon
	
	public function TalkBalloon(container_mc:MovieClip,stageWidth:Number,stageHeight:Number) {
		_fillColor = 0xFFFFFF;
		_lineColor = 0x000000;
		_lineWidth = 2;
		TEXTMARGIN = 3;
		STAGEBALLOONMARGIN = 12;
		ACTORBALLOONMARGIN = 12;
		_container_mc = container_mc;
		_stageHeight = stageHeight;
		_stageWidth = stageWidth;
	}
	
	public function talk( talk_st:String, lipsX:Number, lipsY:Number, actorBoundsRect:Object ):void {
trace("DramTalkBalloon.talk()");
/*
		_balloon_mc = _container_mc.createEmptyMovieClip ("wordBalloon", _container_mc.getNextHighestDepth());
		createText(talk_st);
		//The Width and Height of the Dynamic Textfield
		_balloonWidth = _balloon_mc.balloon_txt.textWidth+(TEXTMARGIN*3);
		_balloonHeight = _balloon_mc.balloon_txt.textHeight+(TEXTMARGIN*3);
		calculateBalloonPosition(lipsX,lipsY,actorBoundsRect,_container_mc.getBounds(_balloon_mc ));
		drawBalloon(_balloon_mc,_balloonWidth, _balloonHeight, TEXTMARGIN );	
*/ 
}
		
	// Place the balloon above the speaker within the stage --------------------
	//
/*	private function calculateBalloonPosition(lipsX:Number, lipsY:Number, actorBoundsRect:Object,stageBoundsRect:Object):void {
		var actorTopY:Number = actorBoundsRect.yMin;
		var stageRightX:Number = stageBoundsRect.xMax;
		var balloonX:Number;
		var balloonY:Number;
		// Calc horizontal position
		// Centered over lips and within margins
		// If actor too close to top shift balloon to one side
		if(actorTopY < (_balloonHeight + STAGEBALLOONMARGIN + ACTORBALLOONMARGIN)) {
			
		} else {
			balloonX = lipsX - (_balloonWidth/2);
			// Too far left
			if(balloonX < STAGEBALLOONMARGIN) {
				balloonX = STAGEBALLOONMARGIN;
			}
		}
		// Too far right
		if((balloonX + _balloonWidth) > (stageRightX - STAGEBALLOONMARGIN)) {
			balloonX = (stageRightX - STAGEBALLOONMARGIN) - _balloonWidth;
		}
		// Calc Y
		balloonY = (actorTopY - _balloonHeight) - ACTORBALLOONMARGIN;
		if(balloonY < STAGEBALLOONMARGIN) {
			balloonY = STAGEBALLOONMARGIN;
		}
	
		_balloon_mc._x = balloonX;
		_balloon_mc._y = balloonY;
	}
	// Create MovieClip and TextField for balloon-----------------------------------
	// and calculate bounds
	private function createText(talk_st:String):void {
	_balloon_mc.createTextField ("balloon_txt",10, TEXTMARGIN, TEXTMARGIN, 120, 50);
	with(_balloon_mc.balloon_txt) {
		multiline = true;
		selectable = false;
		html = false;
		autoSize = "left";
		type = "dynamic";
		wordWrap = true;
	}
	_balloon_mc.balloon_txt.text = talk_st;
	//Text Format
	_balloonFormat = new TextFormat();
	_balloonFormat.font = "Arial";
	_balloonFormat.size = 14;
	_balloonFormat.bold = true;
	_balloonFormat.color = 0x000000;
	_balloon_mc.balloon_txt.setTextFormat (_balloonFormat);
	}
	
	//
	
	private function drawBalloon(target_mc:MovieClip, boxWidth:Number, boxHeight:Number, cornerRadius:Number):void {
		target_mc.lineStyle (_lineWidth, _lineColor, 100);
		target_mc.beginFill( _fillColor , 100);
		with (target_mc) {
			moveTo(cornerRadius, 0);
			lineTo(boxWidth - cornerRadius, 0);
			curveTo(boxWidth, 0, boxWidth, cornerRadius);
			lineTo(boxWidth, cornerRadius);
			lineTo(boxWidth, boxHeight - cornerRadius);
			curveTo(boxWidth, boxHeight, boxWidth - cornerRadius, boxHeight);
			lineTo(boxWidth - cornerRadius, boxHeight);
			lineTo(cornerRadius, boxHeight);
			curveTo(0, boxHeight, 0, boxHeight - cornerRadius);
			lineTo(0, boxHeight - cornerRadius);
			lineTo(0, cornerRadius);
			curveTo(0, 0, cornerRadius, 0);
			lineTo(cornerRadius, 0);
			endFill();
		} 
	}
	*/
	
	public function disappear():void {
//		_balloon_mc.removeMovieClip();
	}
	
	}
}